package com.hisan.freeride.home.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.hisan.freeride.R;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.home.model.LoveCart;


import java.util.List;

/**
 * 爱心车主排行榜适配器
 * Created by yu on 2017/1/17.
 */

public class LoveCartAdapter extends RecyclerView.Adapter{
    private  List<LoveCart> mList;
    private Context mcontext;

   public LoveCartAdapter(Context context,List<LoveCart> list) {
    mList = list;
       mcontext=context;
  }
    public void setNewData(List<LoveCart> list) {
        mList = list;
        notifyDataSetChanged();
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
         return new CartViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.lovecart_item,null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        LoveCart  homeModel=mList.get(position);
        final CartViewHolder viewHolder = (CartViewHolder) holder;
        viewHolder.name.setText(homeModel.getRealname());
        if ((position+1)>3){
            viewHolder.ranking.setTextColor(mcontext.getResources().getColor(R.color.sdarkgray));
        }else {
            viewHolder.ranking.setTextColor(mcontext.getResources().getColor(R.color.order));
        }
        viewHolder.ranking.setText((position+1)+".");
        if (!CollectionUtils.isNullOrEmpty(homeModel.getAvatar())){
            viewHolder.simpleDraweeView.setImageURI(homeModel.getAvatar());
        }else{
            viewHolder.simpleDraweeView.setImageResource(R.mipmap.avator);
        }
        viewHolder.experience.setText(homeModel.getExperience()+"分");
    }

    @Override
    public int getItemCount() {
         return mList != null ? mList.size() : 0;
    }
}
